﻿Imports Microsoft.Win32

Public Class frmEdit
    Public isOK As Boolean = False
    Public sName, sData As String
    Public sType As Integer
    Dim lstData As Dictionary(Of String, frmMain.myValue)
    Dim sNameOld As String
    Private Sub frmEdit_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

    End Sub

    Public Sub SetData(ByVal lst As Dictionary(Of String, frmMain.myValue), _
                       ByVal name As String, Optional ByVal isNew As Boolean = False)
        lstData = lst
        sNameOld = name
        txtName.Text = name
        If isNew Then
            cmbType.SelectedIndex = 0
        Else
            Dim iType As String = lstData(name).Type
            txtData.Text = frmMain.DecodeRegistryData(lstData(name).Data, lstData(name).Type)
            cmbType.SelectedIndex = cmbType.FindString(iType)
        End If
    End Sub

    Private Sub btnOK_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnOK.Click
        For Each item As String In lstData.Keys
            If txtName.Text.ToLower = item.ToLower And txtName.Text.ToLower <> sNameOld.ToLower Then
                ToolTipName.Show("Name existed!", txtName, 1000)
                Return
            End If
        Next
        sName = txtName.Text
        sData = txtData.Text
        sType = cmbType.Text.Substring(0, 1)
        If sType = RegistryValueKind.DWord Then
            If Not Integer.TryParse(sData, New Integer) Then
                ToolTipName.Show("Data not valid!", txtData, 1000)
                Return
            End If
        End If

        isOK = True
        Me.Close()
    End Sub
End Class